package ${package}.${rootArtifactId}.common.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 权限配置
 *
 * @author weidong.lin
 * @date 2021/7/9 15:03
 */
@Component
@ConfigurationProperties(SecurityProperties.PREFIX)
public class SecurityProperties {
    public static final String PREFIX = "project.security";
    private static final List<String> PATH_PATTERNS = Arrays.asList("/**");
    private static final List<String> EXCUTED_PATH_PATTERNS = getExcludePathList();
    /**
     * 允许的访问列表
     */
    private List<String> pathPatterns = new ArrayList<>();
    /**
     * 不允许访问列表
     */
    private List<String> excludePathPatterns = new ArrayList<>();

    public List<String> getPathPatterns() {
        pathPatterns.addAll(PATH_PATTERNS);
        return pathPatterns;
    }

    public void setPathPatterns(List<String> matchers) {
        this.pathPatterns = matchers;
    }

    public List<String> getExcludePathPatterns() {
        excludePathPatterns.addAll(EXCUTED_PATH_PATTERNS);
        return excludePathPatterns;
    }

    public void setExcludePathPatterns(List<String> excludePathPatterns) {
        this.excludePathPatterns = excludePathPatterns;
    }

    public static List<String> getExcludePathList() {
        List<String> list = new ArrayList<>();
        list.add("/error");
        list.add("/static/**");
        list.add("/healthCheck");
        list.add("/wapi/mock/*");
//        list.add("/wapi/callbackRecord/*");
        return list;
    }
}
